package com.cyh.exp.controller;

import com.cyh.exp.mode.Result;
import com.cyh.exp.mode.Task_release;
import com.cyh.exp.mode.Task_status;
import com.cyh.exp.mode.Task_sub;
import com.cyh.exp.service.TaskService;
import org.springframework.security.access.method.P;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
public class TaskController {

    TaskService taskService;

    private TaskController(TaskService taskService){this.taskService=taskService;}

    /**
     * 查询任务
     * @return
     */
    @GetMapping("/index")
    public Result getAllTask(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return taskService.getAllTask(principal.toString());
    }

    /**
     * 任务发布
     */

    @PostMapping("/release")
    public Result InsertTask(@RequestBody Task_release taskRelease){
        System.out.println(taskRelease);
        return taskService.InsertTask(taskRelease);
    }

    /**
     * 任务提交
     */

    @PostMapping("/submit")
    public Result SubTask(@RequestBody Task_sub task_sub){
        return taskService.SubTask(task_sub);
    }

    /**
     * 任务状态修改
     */

    @PostMapping("/submit/Examine")
    public Result Examine(@RequestBody Task_status task_status){
        return taskService.Examine(task_status);
    }

    @GetMapping("/submit/getSub")
    public Result getSubCont(@RequestParam("tid") String tid){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return taskService.getSubCont(tid,principal.toString());
    }

    @GetMapping("/submit/query")
    public Result getCont(@RequestParam("id") String id){
        return taskService.getCont(id);
    }


}
